/*
 * Copyright 2007-2008 Brian Cavalier
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.bc.iterate.view;

import java.util.NoSuchElementException;

/**
 * StepIntegerRangeView is a synthetic iterator that iterates over a range
 * of integers, stepping by a specified amount.  There is no Collection
 * backing an IntegerRangeView.
 * 
 * @author Brian Cavalier
 * @see IntegerRangeView
 */
public class StepIntegerRangeView extends IntegerRangeView
{
	private int step;

	public StepIntegerRangeView() {
		super();
	}
		
	public StepIntegerRangeView(int start, int end, int step) {
		super(start, end);
		this.step = step;
	}
	
	public StepIntegerRangeView by(int step) {
		this.step = step;
		return this;
	}
	
	@SuppressWarnings({"RefusedBequest"})
    @Override
    public Integer next() {
        if(_start >= _end) {
            throw new NoSuchElementException();
        }
        int current = _start;
		_start += step;
		return current;
	}
}
